/**
 * Created by Administrator on 2017/3/13 0013.
 */
Page2={
    Create:function(){
        var page={};
        var whole=new PIXI.DisplayObjectContainer();
        var Idx=-1;
        var arr=[];

        for(var z=0;z<150*85;z++) {
            var square = new PIXI.Graphics();
            square.beginFill(0x999999, 1);
            square.drawRect(0, 0, 10, 10);
            square.x=pixiStageW/2-square.width/2;square.y=pixiStageH/2-square.height/2;
            // square.x=pixiStageW/2+1200*Math.random()-600;square.y=pixiStageH/2+500*Math.random()-250;
            square.alpha=0;
            whole.addChild(square);
            arr.push(square);
        }
        var bg2=new PIXI.Graphics();
        bg2.beginFill(0xffffff,1);
        bg2.drawRect(0,0,1480,800);

        var whiteFrame=new PIXI.Sprite();
        for(var y=0;y<4;y++) {
            var frame = new PIXI.Graphics();
            frame.beginFill(0xffffff,1);
            switch (y){
                case 0:frame.drawRect(0,0,1480,30);break;
                case 1:frame.drawRect(0,30,20,800-30);break;
                case 2:frame.drawRect(200,30,1480-200,800-30);break;
                case 3:frame.drawRect(20,270,180,800-270);break;
            }
            whiteFrame.addChild(frame);
        }

        var line1=new PIXI.Graphics();
        line1.lineStyle(2,0x999999,1);
        line1.moveTo(0,0);
        line1.lineTo(0,766);
        var line2=new PIXI.Graphics();
        line2.lineStyle(2,0x07377f,1);
        line2.moveTo(0,0);line2.lineTo(1220,0);

        var textTitle= new PIXI.Text('网元详情',{fontFamily : 'Arial', fontSize: 40, fill : 0x000000, align : 'center'});
        var arr_text=[];
        for(var z=0;z<20;z++) {
            var content="";
            switch(z){
                case 0:content="MOI名称";break;
                case 1:content="友好名称";break;
                case 2:content="设备描述";break;
                case 3:content="操作系统类型";break;
                case 4:content="是否虚拟设备";break;
                case 5:content="设备型号";break;
                case 6:content="数据域";break;
                case 7:content="所属机房";break;
                case 8:content="用户名";break;
                case 9:content="密码";break;
                case 10:content="IP地址";break;
                case 11:content="备用IP地址段";break;
                case 12:content="端口";break;
                case 13:content="KM接口IP地址";break;
                case 14:content="Agent的IP地址";break;
                case 15:content="Agent版本";break;
                case 16:content="信号光波长";break;
                case 17:content="同步光波长";break;
                case 18:content="通信状态";break;
                case 19:content="软件版本";break;
            }
            var text = new PIXI.Text(content, {fontFamily: 'Arial', fontSize: 20, fill: 0x000000});
            text.x =650+z%2*650-text.width-20;text.y=264+60*Math.floor(z/2);
            arr_text.push(text);
            text.alpha=0;
        }
        var arr_info=[];

        for(var z=0;z<20;z++){
            var infoWhole=new PIXI.Sprite();
            var infoBG=new PIXI.Graphics();
            infoBG.lineStyle(2, 0x000000, 1);
            infoBG.beginFill(0xffffff, 1);
            infoBG.drawRect(0, 0, 358,44);
            infoBG.endFill();
            infoBG.x =650+z%2*650;infoBG.y=255+60*Math.floor(z/2);
            infoWhole.addChild(infoBG);

            var infoText=new PIXI.Text('data',{fontFamily:'Arial',fontSize:20,fill:0x000000});
            infoText.x=infoBG.x+10;infoText.y=infoBG.y+infoBG.height/2-infoText.height/2;
            infoWhole.addChild(infoText);
            arr_info.push(infoWhole);
            infoWhole.alpha=0;
        }


        var btn1=Btn2.Create(146,44,"设备图示","http://www.baidu.com");
        var btn2=Btn2.Create(146,44,"机房图示","http://www.baidu.com");
        var btn3=Btn2.Create(146,44,"查看告警","http://www.baidu.com");
        var btn4=Btn2.Create(146,44,"查看状态","http://www.baidu.com");
        var btnClose=Btn2.Create(146,44,"离开","Close");

        // whole.addChild(bg2);
        whole.addChild(whiteFrame);
        whole.addChild(textTitle);
        whole.addChild(line1);
        whole.addChild(line2);
        for(var z=0;z<arr_text.length;z++){
            whole.addChild(arr_text[z]);
        }
        for(var z=0;z<arr_info.length;z++){
            whole.addChild(arr_info[z]);
        }
        whole.addChild(btn1.RW());
        whole.addChild(btn2.RW());
        whole.addChild(btn3.RW());
        whole.addChild(btn4.RW());
        whole.addChild(btnClose.RW());

        whiteFrame.x=pixiStageW/2-1480/2;whiteFrame.y=pixiStageH/2+25-9-800/2;

        bg2.x=pixiStageW/2-bg2.width/2;bg2.y=pixiStageH/2+25-9-bg2.height/2;
        line1.x=447;line1.y=185;
        line2.x=464;line2.y=238;
        textTitle.x=467;textTitle.y=185;
        btn1.RW().x=780;btn1.RW().y=900;
        btn2.RW().x=btn1.RW().x+btn1.RW().width+15;btn2.RW().y=btn1.RW().y;
        btn3.RW().x=btn2.RW().x+btn2.RW().width+15;btn3.RW().y=btn1.RW().y;
        btn4.RW().x=btn3.RW().x+btn3.RW().width+15;btn4.RW().y=btn1.RW().y;
        btnClose.RW().x=1514;btnClose.RW().y=btn1.RW().y;

        whiteFrame.alpha=0;
        bg2.alpha=0;
        line1.alpha=0;
        line2.alpha=0;
        textTitle.alpha=0;
        btn1.RW().alpha=0;btn2.RW().alpha=0;btn3.RW().alpha=0;btn4.RW().alpha=0;btnClose.RW().alpha=0;

        function squareCombine(bl){
            if(bl) {
                for (var z = 0; z < arr.length; z++) {
                    var xx = Math.floor(z / 85) * 10 + pixiStageW / 2 - 1500 / 2;
                    var yy = z % 85 * 10 + pixiStageH / 2 - 850 / 2;
                    var setAlpha=0.5;
                    if(xx>=pixiStageW/2-1500/2+3*10&&xx<=pixiStageW/2-1500/2+20*10){
                        if(yy>=pixiStageH/2-850/2+7*10&&yy<=pixiStageH/2-850/2+30*10){
                            setAlpha=0;
                        }
                    }
                    TweenMax.to(arr[z], 1 + Math.random() * 0.5, {delay: 0.9, alpha: setAlpha, x: xx, y: yy, ease: Cubic.easeInOut});
                }
            }
            else{
                for (var z = 0; z < arr.length; z++) {
                    var xx = arr[z].x+1000*Math.random()-500;
                    var yy = arr[z].y+600*Math.random()-300;
                    TweenMax.to(arr[z], 1 + Math.random() * 0.5, {delay: 0.2, alpha: 0, x: xx, y: yy, ease: Cubic.easeInOut});
                }
            }
        }

        function textAppearance(bl){
            if(bl){
            for(var z=0;z<arr_text.length;z++){
                TweenMax.to(arr_text[z],0.7,{delay:3+0.03*z,alpha:1,ease:Cubic.easeOut});
                TweenMax.to(arr_info[z],0.7,{delay:3.1+0.03*z,alpha:1,ease:Cubic.easeOut});

            }
            }
            else{
                for(var z=0;z<arr_text.length;z++){
                    TweenMax.to(arr_text[z],0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
                    TweenMax.to(arr_info[z],0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
                }
            }
        }

        function dataCreate(){
            console.log(Idx);
            for(var z=0;z<arr_info.length;z++){
                arr_info[z].getChildAt(1).text=netElementData[Idx*7];
            }
        }


        page.DoIt=function(){

        }

        var inDelay=0.5;
        page.In=function(getIdx){
            Idx=getIdx;
            dataCreate();
            line1.y=185-40;line2.x=464+40;textTitle.x=467-30;

            TweenMax.to(bg2,0.7,{delay:1.8+inDelay,alpha:0.8,ease:Cubic.easeOut});
            TweenMax.to(whiteFrame,0.7,{delay:1.8+inDelay,alpha:0.8,ease:Cubic.easeOut});
            TweenMax.to(line1,0.7,{delay:2.4+inDelay,alpha:0.8,y:185,ease:Cubic.easeOut});
            TweenMax.to(line2,0.7,{delay:2.6+inDelay,alpha:0.8,x:464,ease:Cubic.easeOut});
            TweenMax.to(textTitle,0.7,{delay:2.8+inDelay,alpha:0.8,x:467,ease:Cubic.easeOut});

            squareCombine(true);
            textAppearance(true);

            setTimeout(function(){
                btn1.enabled=true;btn2.enabled=true;btn3.enabled=true;btn4.enabled=true;btnClose.enabled=true;
            },3500+inDelay*1000)
            TweenMax.to(btn1.RW(),0.7,{delay:3.5+inDelay,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(btn2.RW(),0.7,{delay:3.6+inDelay,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(btn3.RW(),0.7,{delay:3.7+inDelay,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(btn4.RW(),0.7,{delay:3.8+inDelay,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(btnClose.RW(),0.7,{delay:4.0+inDelay,alpha:1,ease:Cubic.easeOut});
        }
        page.Out=function(){

            TweenMax.to(bg2,0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(whiteFrame,0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(line1,0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(line2,0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(textTitle,0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});

            squareCombine(false);
            textAppearance(false);

            btn1.enabled=false;btn2.enabled=false;btn3.enabled=false;btn4.enabled=false;btnClose.enabled=false;
            TweenMax.to(btn1.RW(),0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(btn2.RW(),0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(btn3.RW(),0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(btn4.RW(),0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(btnClose.RW(),0.7,{delay:0.4,alpha:0,ease:Cubic.easeOut});
        }

        page.ReturnWhole=function(){
            return whole;
        };

        return page;
    }
}
